package vn.bus.models;

import java.sql.Connection;
import java.util.ArrayList;

import vn.bus.dao.Database;
import vn.bus.dao.StationDAO;
import vn.bus.dto.StationDTO;

public class StationManager {

	public ArrayList<StationDTO> getAllStations()throws Exception {
		ArrayList<StationDTO> allStations = null;
		try {
			    Database database= new Database();
			    Connection connection = database.Get_Connection();
			    StationDAO Station = new StationDAO();
			    allStations = Station.getAllStations(connection);
			    connection.close();
		
		} catch (Exception e) {
			throw e;
		}
		return allStations;
	}
	
	public ArrayList<StationDTO> textSearch(String str)throws Exception {
		ArrayList<StationDTO> textSearchStations = null;
		try {
			    Database database= new Database();
			    Connection connection = database.Get_Connection();
			    StationDAO Station = new StationDAO();
			    textSearchStations = Station.textSearch(connection, str);
			    connection.close();
		
		} catch (Exception e) {
			throw e;
		}
		return textSearchStations;
	}
	
	public ArrayList<StationDTO> clickSearch(double lat, double lon)throws Exception {
		ArrayList<StationDTO> clickSearchStations = null;
		try {
			    Database database= new Database();
			    Connection connection = database.Get_Connection();
			    StationDAO Station = new StationDAO();
			    clickSearchStations = Station.clickSearch(connection, lat, lon);
			    connection.close();
		
		} catch (Exception e) {
			throw e;
		}
		return clickSearchStations;
	}
}
